<template>
	<view class="register">
	
		<view class="content">
			<!-- 头部logo -->
			<view class="header">
				<image :src="logoImage"></image>
			</view>
			<!-- 主体 -->
			<view class="main">
				<wInput
					v-model="name"
					type="text"
					maxlength="10"
					placeholder="代理商名称"
				></wInput>
				<view class="prompt">2-5位汉字</view>
				<wInput
					v-model="mobile"
					type="text"
					maxlength="11"
					placeholder="联系电话"
				></wInput>
				<view class="prompt">联系人的手机号</view>
				<wInput
					v-model="link_man"
					type="text"
					maxlength="10"
					placeholder="联系人"
				></wInput>
				<view class="prompt">2-5位汉字</view>
				<wInput
					v-model="account"
					type="text"
					maxlength="12"
					placeholder="登录账号"
				></wInput>
				<view class="prompt">6-12位数字加字母</view>
				<wInput
					v-model="password"
					type="password"
					maxlength="16"
					placeholder="登录密码"
					isShowPass
				></wInput>
				<view class="prompt">6-16位数字加字母</view>
<!-- 				<wInput
					v-model="verCode"
					type="number"
					maxlength="4"
					placeholder="验证码"
					
					isShowCode
					ref="runCode"
					@setCode="getVerCode()"
				></wInput> -->
					
			</view>
				
			<wButton 
				class="wbutton"
				text="注 册"
				:rotate="isRotate" 
				@click.native="startReg()"
			></wButton>
			
			<!-- 底部信息 -->
<!-- 			<view class="footer">
				<text 
					@tap="isShowAgree" 
					class="cuIcon"
					:class="showAgree?'cuIcon-radiobox':'cuIcon-round'"
				> 同意</text>
				<navigator url="" open-type="navigate">《协议》</navigator>
			</view> -->
		</view>
	</view>
</template>

<script>
	let that;
	import wInput from '../../components/watch-login/watch-input.vue' //input
	import wButton from '../../components/watch-login/watch-button.vue' //button
	
	export default {
		data() {
			return {
				//logo图片 base64
				logoImage:'https://qiniu.hiima.cn/98c312cfd249cd0de18c5d76cded4bfd9f03ceea1617267130.png',
				phoneData:'', // 用户/电话
				password:'', //密码
				name:'',
				mobile:'',
				link_man:'',
				account:'',
				verCode:"", //验证码
				// showAgree:true, //协议是否选择
				isRotate: false, //是否加载旋转
			}
		},
		components:{
			wInput,
			wButton,
		},
		mounted() {
			that= this;
		},
		methods: {
			// isShowAgree(){
			// 	//是否选择协议
			// 	that.showAgree = !that.showAgree;
			// },
			// getVerCode(){
			// 	//获取验证码
			// 	if (that.phoneData.length != 11) {
			// 	     uni.showToast({
			// 	        icon: 'none',
			// 			position: 'bottom',
			// 	        title: '手机号不正确'
			// 	    });
			// 	    return false;
			// 	}
			// 	console.log("获取验证码")
			// 	this.$refs.runCode.$emit('runCode'); //触发倒计时（一般用于请求成功验证码后调用）
			// 	uni.showToast({
			// 	    icon: 'none',
			// 		position: 'bottom',
			// 	    title: '模拟倒计时触发'
			// 	});
				
			// 	setTimeout(function(){
			// 		that.$refs.runCode.$emit('runCode',0); //假装模拟下需要 终止倒计时
			// 		uni.showToast({
			// 		    icon: 'none',
			// 			position: 'bottom',
			// 		    title: '模拟倒计时终止'
			// 		});
			// 	},3000)
			// },
		    startReg() {
				//注册
				if(this.isRotate){
					//判断是否加载中，避免重复点击请求
					return false;
				}
				if(this.name.length<1||this.name.length>5){
					 uni.showToast({
				        icon: 'none',
						position: 'bottom',
				        title: '代理商名称格式错误'
				    });
				    return false;
				}
				if(!(/(^1[3456789]\d{9}$)/.test(this.mobile))){
					uni.showToast({
					    icon: 'none',
						position: 'bottom',
					    title: '联系电话格式错误'
					});
					return false;
				}
				if(this.link_man.length<1||this.link_man.length>5){
					uni.showToast({
					    icon: 'none',
						position: 'bottom',
					    title: '联系人格式错误'
					});
					return false;
				}
				
				if (!(/(^[a-zA-Z0-9_-]{6,12}$)/.test(this.account))) {
				   uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '登录账户格式错误'
				   });
				   return false;
				}
		        if (!(/(^[a-zA-Z0-9_-]{6,16}$)/.test(this.password))) {
		            uni.showToast({
		                icon: 'none',
						position: 'bottom',
		                title: '登录密码格式错误'
		            });
		            return false;
		        }
				// if (this.verCode.length != 4) {
				//     uni.showToast({
				//         icon: 'none',
				// 		position: 'bottom',
				//         title: '验证码不正确'
				//     });
				//     return false;
				// }
				// console.log("注册成功")
				that.isRotate=true
				this.$request.httpTokenRequest({
					url: '/admin/master/setAgent',
					method: 'POST',
					data: {
						name: that.name,
						mobile: that.mobile,
						link_man: that.link_man,
						account: that.account,
						password: that.password,
					},
					needToken:false,
				}).then(res => {
					if (res.data.code === 200) {
						that.isRotate=false;
						uni.showToast({
						    icon:'success' ,
							position: 'bottom',
						    title: '注册成功'
						});
						setTimeout(()=>{
							uni.redirectTo({
								url: 'login'
							})
						},1000)
					}else{
						that.isRotate=false;
						uni.showToast({
						    icon:'none' ,
							position: 'bottom',
						    title: res.data.msg
						});
					}
				}, error => {
				});
				// setTimeout(function(){
				// 	that.isRotate=false
				// },3000)
		    }
		}
	}
</script>

<style>
	@import url("../../components/watch-login/css/icon.css");
	@import url("./css/main.css");
	.prompt{
		margin-left: 30rpx;
		font-size: 20rpx;
		color: #999;
	}
</style>